---
# task file for glpi-server

- name: install packages
  ansible.builtin.apt:
    pkg:
    - apache2
    - mariadb-server
    - certbot
    - pip
    - php
    - php-xml
    - php-curl
    - php-gd
    - php-intl
    - php-mysqli
    - php-mbstring
    - php-ldap
    - php-bz2
    - php-zip
    state: latest

- name: install pymysql
  ansible.builtin.pip:
    name: pymysql
    state: present
  environment:
    http_proxy: 'http://s4.okb3.local:3665'
    https_proxy: 'http://s4.okb3.local:3665'

- name: glpi database
  community.mysql.mysql_db:
    name: "{{ glpi_db_name }}"
    state: present
    login_unix_socket: /run/mysqld/mysqld.sock

- name: glpi user
  community.mysql.mysql_user:
    name: "{{ glpi_user }}"
    password: "{{ glpi_user_password }}"
    priv: "{{ glpi_db_name }}.*:ALL,GRANT"
    login_unix_socket: /run/mysqld/mysqld.sock


- name: glpi package
  ansible.builtin.unarchive:
    src: https://github.com/glpi-project/glpi/releases/download/10.0.9/glpi-10.0.9.tgz
    dest: /var/www/html/
    remote_src: yes
    creates: /var/www/html/glpi

- name: access control
  ansible.builtin.file:
    path: /var/www/html/glpi
    mode: 0775
    owner: www-data
    group: www-data
    recurse: true

- name: apache2 configuration
  ansible.builtin.copy:
    src: glpi.conf
    dest: /etc/apache2/sites-available/glpi.conf
  notify:
  - restart apache2

- name: apache2 enable glpi
  ansible.builtin.command:
    cmd: a2ensite glpi.conf
    creates: /etc/apache2/sites-enabled/glpi.conf